package com.ruoyi.system.mapper;

import java.util.List;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.system.domain.ByOrder;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 【请填写功能名称】Mapper接口
 *
 * @author ruoyi
 * @date 2023-05-27
 */
@Mapper
public interface ByOrderMapper {
    @Select("SELECT * FROM `by_order` where wx_id = #{userid} and id = #{id}")
    JSONObject orderDetailForidAndUserid(@Param("id") String id,@Param("userid") String userid);

    @Select("SELECT * FROM `by_order` where `status` = 1 and wx_id = #{userid} ORDER BY addtime DESC LIMIT 0,1")
    JSONObject orderDetailByUserid(@Param("userid") String userid);

    // 当前日期帮手被预约详情
    @Select("SELECT CONCAT('日期：',#{date},',已备预约时间：',GROUP_CONCAT(time)) payTime FROM `by_order` where `status` != 0 and  bs_id = #{bsid} and date = #{date}")
    String BsDateTimeDetailByBsidAndDate(@Param("bsid") String bsid,@Param("date") String date);

    // 查询当前日期帮手的预约情况
    @Select("SELECT * from by_order where `status` != '0' and bs_id = #{bsid} and date = #{date}")
    List<ByOrder> getBsOrderListByBsIdAndDate(@Param("bsid") String bsid,@Param("date") String date);


    // 订单详情
    @Select("SELECT a.lxr,a.phone,a.address,a.`status`,a.km,a.date,a.time,a.starttime,a.endtime,b.`name`,b.mobile,a.dprice,a.orderprice,a.allprice,a.payprice,a.id FROM `by_order` a,by_bs b where a.bs_id = b.id and a.id = #{id}")
    JSONObject orderDetailById(@Param("id") String id);


    @Update("update by_order set pay_img = #{url} where id = #{id}")
    int updateOrder_PayimgById(@Param("id") String id,@Param("url") String url);

    @Update("update by_order set orderimg = #{url} where id = #{id}")
    int updateOrder_imgById(@Param("id") String id,@Param("url") String url);

    @Select("SELECT * FROM `by_order` where pay_id = #{orderSn}")
    List<ByOrder> getOrderPayByOrderSn(@Param("orderSn") String orderSn);


    @Select("SELECT * FROM `by_order` where dj_pay_id = #{orderSn}")
    List<ByOrder> getOrderByYfOrderSn(@Param("orderSn") String orderSn);

    @Select("SELECT * from by_order where `status` = 1 and wx_id = #{wxid} ORDER BY addtime DESC LIMIT 0,1")
    ByOrder getOrderByWxIdOne(@Param("wxid") String wxid);

    // 根据帮手的微信id，获取帮手的订单信息
    @Select("SELECT a.*,b.`name` FROM `by_order` a,by_bs b where a.bs_id = b.id and b.wxid = #{wxid} ORDER BY a.addtime desc")
    List<JSONObject> getOderByBsIdWxId(@Param("id") String id,@Param("wxid") String wxid);

    // 获取当前订单的时间-分钟
    @Select("SELECT TIMESTAMPDIFF(MINUTE,starttime,endtime) FROM `by_order` where id = #{id}")
    String orderMINUTE(@Param("id") String id);
    //停止计时
    @Update("update by_order set endtime=now() where id = #{id}")
    int stopOrder(@Param("id") String id);

    //开始计时  扫码开启计时
    @Update("update by_order set starttime=now(),`status`='4' where id = #{id}")
    int startWxCodeOrder(@Param("id") String id);

    //开始计时
    @Update("update by_order set starttime=now(),`status`='4' where wx_id = #{wxid} and id = #{id}")
    int startOrder(@Param("id") String id,@Param("wxid") String wxid);

    //进行订单的取消
    @Update("update by_order set status = '7' where id = #{id}")
    int quitOrder(@Param("id") String id);

    // 根据家长微信id获取全部订单信息
    @Select("SELECT a.*,b.`name`,(SELECT count(0) from by_order_eval c where a.id = c.order_id) count from by_order a,by_bs b where b.id = a.bs_id and a.status = #{status} and a.wx_id = #{wxid} ORDER BY a.addtime desc")
    List<JSONObject> getOrderByWxIdAndStatus(@Param("wxid") String wxid,@Param("status") String status);

    // 根据家长微信id获取全部订单信息
    @Select("SELECT a.*,b.`name`,(SELECT count(0) from by_order_eval c where a.id = c.order_id) count,b.img img from by_order a,by_bs b where b.id = a.bs_id and a.wx_id = #{wxid} ORDER BY a.addtime desc")
    List<JSONObject> getOrderByWxId(@Param("wxid") String wxid);

    // 根据帮手的微信id，获取帮手的订单信息
    @Select("SELECT a.*,b.`name`,(SELECT count(0) from by_order_eval c where a.id = c.order_id) count FROM `by_order` a,by_bs b where a.bs_id = b.id and b.wxid = #{wxid} ORDER BY a.addtime desc")
    List<JSONObject> getOderByBsWxId(@Param("wxid") String wxid);
    // 根据帮手微信id获取全部订单信息
    @Select("SELECT a.*,b.`name`,(SELECT count(0) from by_order_eval c where a.id = c.order_id) count from by_order a,by_bs b where b.id = a.bs_id and a.status = #{status} and b.wxid = #{wxid} ORDER BY a.addtime desc")
    List<JSONObject> getOrderByBsWxIdAndStatus(@Param("wxid") String wxid,@Param("status") String status);

    /**
     * 查询【请填写功能名称】
     *
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    public ByOrder selectByOrderById(Long id);

    /**
     * 查询【请填写功能名称】列表
     *
     * @param byOrder 【请填写功能名称】
     * @return 【请填写功能名称】集合
     */
    public List<ByOrder> selectByOrderList(ByOrder byOrder);

    /**
     * 新增【请填写功能名称】
     *
     * @param byOrder 【请填写功能名称】
     * @return 结果
     */
    public int insertByOrder(ByOrder byOrder);

    /**
     * 修改【请填写功能名称】
     *
     * @param byOrder 【请填写功能名称】
     * @return 结果
     */
    public int updateByOrder(ByOrder byOrder);

    /**
     * 删除【请填写功能名称】
     *
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    public int deleteByOrderById(Long id);

    /**
     * 批量删除【请填写功能名称】
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteByOrderByIds(Long[] ids);

    @Select("select status from by_order where id =#{orderid}")
    String isStartOrEnd(@Param("orderid") String orderid);
}
